package com.aaa.controller.sds;

import cn.hutool.json.JSONConfig;
import cn.hutool.json.JSONUtil;
import com.aaa.controller.BaseController;
import com.aaa.entity.system.PageEnty;
import com.aaa.entity.Result;
import com.aaa.entity.sds.PlanSds;

import com.aaa.service.sds.PlanSdsService;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;


/**
 * 测试计划sds(PlanSds)表控制层
 *
 * @author makejava
 * @since 2022-09-01 19:18:03
 */
@RestController
@RequestMapping("planSds")
public class PlanSdsController extends BaseController {
    /**
     * 服务对象
     */
    @Autowired
    private PlanSdsService planSdsService;

    /**
     * 分页查询
     *
     * @param planSds 筛选条件
     * @param pageEnty      分页对象
     * @return 查询结果
     */
    @RequestMapping("/queryAll.do")
    public String queryAll(PageEnty pageEnty, PlanSds planSds) {
        Page page = planSdsService.queryAllPlanSdsPage(pageEnty, planSds);
        JSONConfig jsonConfig = JSONConfig.create().setDateFormat("yyyy-MM-dd HH:mm:ss");
        return JSONUtil.toJsonStr(success( page.getTotal(),page.getResult()), jsonConfig);

    }
    /**
     * @create by: Teacher马
     * @description:添加
     * @create time:

     * @return
     */
    @RequestMapping("/saveUser.do")
    public Result saveUser(PlanSds planSds  ){
        boolean savePlanScl = planSdsService.savePlanSds(planSds);
        if (savePlanScl){
            return success();
        }else {
            return fail();
        }

    }
    /**
     * @create by: Teacher马
     * @description:删除
     * @create time:

     * @return
     */
    @RequestMapping("/deleteUser.do")
    public Result deleteUser(int[] id){
        boolean deletePlanScl = planSdsService.deletePlanSds(id);
        if (deletePlanScl){
            return success();
        }else {
            return fail();
        }
    }
    /**
     * @create by: Teacher马
     * @description:修改
     * @create time:

     * @return
     */
    @RequestMapping("/updateUser.do")
    public Result updateUser(PlanSds planSds)  {
        boolean updatePlanScl = planSdsService.updatePlanSds(planSds);
        if (updatePlanScl){
            return success();
        }else {
            return fail();
        }
    }

    /**
     * @create by:
     * @description: 题目唯一性校验
     * @create time: 2022/7/14 17:00
     * @param "QuestionFpa"
     * @return MyReturn
     */
    @GetMapping("repetitionName.do")
    public Result repetitionName(PlanSds planSds){
        boolean b = this.planSdsService.repetitionName(planSds);
        if (b){
            return success("问题可用");
        }
        return fail("问题重复，不可用");
    }

    /**
     * @create by: Teacher马
     * @description: 下拉框
     * @create time:

     * @return
     */
    @RequestMapping("queryAllById.do")
    public Result queryAllById(){
        List<PlanSds> planSds = planSdsService.queryAll();
        System.out.println("输出的下拉框的内容"+planSds);
        return success(planSds);
    }
    /**
     * @create by: Teacher马
     * @description: 如果使用了restController注解，页面跳转不能使用上面的String
     * @create time:

     * @return
     */
    @RequestMapping("/planSdsUser.do")
    public ModelAndView planSclUser(ModelAndView modelAndView ){
        modelAndView.setViewName("sds/showPlanSds");
        return  modelAndView;
    }

}

